package liuch.foreach;

import com.sun.xml.internal.ws.server.UnsupportedMediaException;

import java.util.Iterator;
import java.util.Map;
import java.util.function.Consumer;

/**
 * 〈一句话功能简述〉<br>
 *      实现Iterable接口，使类具备迭代器功能，可以用for()循环
 * @author 17101651 on 2018/5/17.
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
public class IterableClass implements Iterable<String> {

    String[] words = ("aa bb cc dd ee ff gg hh ii jj kk ll mm nn oo pp qq rr ss tt").split(" ");

    @Override
    public Iterator<String> iterator() {
        return new Iterator<String>() {

            private int index = 0;

            @Override
            public boolean hasNext() {
                return index < words.length;
            }

            @Override
            public String next() {
                return words[index++];
            }

            @Override
            public void remove() {
                throw new UnsupportedMediaException();
            }
        };
    }

    public static void main(String[] args) {
        for (String s : new IterableClass()) {
            System.out.println(s + " ");
        }
        for (Map.Entry entry : System.getenv().entrySet()) {
            System.out.println(entry.getKey() + " : " + entry.getValue());
        }
    }
}
